#ifndef MOBJECT_H
#define MOBJECT_H

#include "memorypool.h"

/**
 * @brief The MObject class
 * This class encapsulates operator new/delete with methods from MemoryPool.
 * Any classes that inherit from MObject will allocate memory on memory pool
 * instance handled by MObject by default.
 */

class MObject
{
    static MemoryPool* spPoolInstance;

public:
    static MemoryPool& rGetMemoryPool( size_t initialBlockSize= DEFAULT_BLOCK_SIZE );
    static void destroyMemoryPool();
    MObject();

    inline void* operator new (size_t size)
    {
        MemoryPool& memPool = rGetMemoryPool();
        return memPool.allocate(size);
    }

    inline void operator delete ( void* ptr )
    {
        MemoryPool& memPool = rGetMemoryPool();
        memPool.recycle(ptr);
    }
};

#endif // MOBJECT_H
